<template>
	<view class="content">
		
		<view class="" v-for="(item,index) in list" :key="index">
			<view class="xsname" >{{item.name}}</view>
			<view class="xscontent" v-html="item.content"></view>
		</view>
		<uni-load-more :loadingType="loadingType" :contentText="contentText"  ></uni-load-more>
	</view>
</template>

<script>
import getdata from '@/common/ajax.js';		
import uniLoadMore from '@/components/uni-load-more.vue';
var
	page = 1,
	timer = null,
	pages = 1,
	more = null;
	export default {
		components: {uniLoadMore},
		data() {
			return {
				info:'',
				conttent:'',
				ceshi:'',//测试
				list:[],
				loadingText: '加载中...',
				loadingType: 0, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '我也是有底线的~',
				},
			}
		},
		onPullDownRefresh: function() {
			//下拉刷新
			this.detail()
			more = this.info.novel_id//将章节ID重新赋予下拉参数
		},
		onReachBottom: function() {
			//上拉加载
			if (page <= pages) {
					this.getmore();
			}else{
					this.loadingType = 2
			}
		},
		onLoad(option){
			this.info = option
			this.detail()
			more = option.novel_id//将章节ID赋予下拉参数
		},
		methods: {
			detail(){
				//小说详情
				var _this = this
				var token = uni.getStorageSync('token')
				var data = {
					novel_id:_this.info.id,//小说id
					section_id:_this.info.novel_id//小说章节id
				}
				uni.showLoading({
				    title: '加载中'
				});
				uni.request({
					url: getdata.websiteUrl + '/novel/detail',
					header:{'content-type': "application/x-www-form-urlencoded",token:token},
					dataType: 'json',
					method: 'POST',
					data:data,
					success: res => {
						console.log(res)
						uni.stopPullDownRefresh()
						uni.hideLoading();
						if(res.data.code == 1){
							_this.list = []
							_this.list =_this.list.concat(res.data.data) 
						}else{
							getdata.shou(res.data.msg)
						}
					},
					fail: res => {
						uni.hideLoading();
						uni.stopPullDownRefresh()
						getdata.shou('服务器断开链接')
					}
				});
			},
			getmore(){
				//分页
				var _this = this
				var token = uni.getStorageSync('token')
				more++
				console.log(more,_this.info.novel_id)
				var data = {
					novel_id:_this.info.id,//小说id
					section_id:more//小说章节id
				}
				console.log(data)
				uni.request({
					url: getdata.websiteUrl + '/novel/detail',
					header:{'content-type': "application/x-www-form-urlencoded",token:token},
					dataType: 'json',
					method: 'POST',
					data:data,
					success: res => {
						console.log(res)
						if(res.data.code == 1 ){
							if(res.data.data == null || res.data.data == '' || res.data.data == undefined){
								getdata.shou('已经是最后一章了')
								_this.loadingType = 2
							}else{
								_this.list =_this.list.concat(res.data.data) 
							}
							
						}else{
							_this.loadingType = 2
							if(res.data.msg == '参数异常！'){
								getdata.shou('已经是最后一章了')
								
							}else if(res.data.data == null || res.data.data == '' || res.data.data == undefined){
								getdata.shou('已经是最后一章了')
							}else{
								getdata.shou(res.data.msg)
							}
						}
					},
					fail: res => {
						getdata.shou('服务器断开链接')
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.content{
	width: 100%;
	box-sizing: border-box;
	padding: 30rpx;
	.xsname{
		font-size: 40rpx;
		text-align: center;
		color: #000000;
		margin-bottom: 30rpx;
	}
	.xscontent{
		color: #000000;
		line-height: 1.5;
		p{
			span{
				font-size: 40rpx !important;
			}
			a{
				font-size: 40rpx !important;
			}
		}
	}
}
</style>
